﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using MacViet.DataBaseAPI;

[AjaxPro.AjaxNamespace("Ajax_Control_Appointment_app")]
public partial class Control_Appointment_UCAppoint : System.Web.UI.UserControl
{
    private static int acc_id = 0;
    private APPOINTMENTSDataAPI app = new APPOINTMENTSDataAPI();
    private SERVICE_CATEGROIESDataAPI cate = new SERVICE_CATEGROIESDataAPI();
    private SERVICESDataAPI ser = new SERVICESDataAPI();
    private CLIENTSDataAPI cl = new CLIENTSDataAPI();

    private const string STATUS = "WAIT";
    public DataTable dtResult = new DataTable();
    private MyResult result = new MyResult();
    public DataTable dtRes = new DataTable();
    private string acc_email = string.Empty;
    PRODUCTSDataAPI product = new PRODUCTSDataAPI();
    APPOINTMENTSDataAPI appmore = new APPOINTMENTSDataAPI();
    BILLDataAPI BILL = new BILLDataAPI();
    private int app_id=1 ;  

    protected void Page_Load(object sender, EventArgs e)
    {
        //btnSave.Attributes.Add("OnClick", "return SaveClick(this);");
        if (!IsPostBack)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(Control_Appointment_UCAppoint));
            if (Session["acc_id"] != null)
                acc_id = int.Parse(Session["acc_id"].ToString());
            if (Request.QueryString["APP_ID"] != null && Request.QueryString["APP_ID"].ToString() != string.Empty)
                app_id = int.Parse(Request.QueryString["APP_ID"].ToString());
            string getdate = DateTime.Now.ToShortDateString();
            dtResult = appmore.getMore(acc_id,getdate);
            grvShowApp.DataSource = dtResult;
            grvShowApp.DataBind();          
        } 
       
    }

    //[AjaxPro.AjaxMethod]
    //public DataSet loadEmployeeSpa(string dateTime, string time)
    //{
    //    DateTime dateApp = Convert.ToDateTime(dateTime);//08/27/2010        
    //    string[] strarry = time.Split(' ');
    //    string result = strarry[0].ToString() + ":00 " + strarry[1].ToString();
    //    DateTime timeApp = Convert.ToDateTime(dateTime + " " + result);
    //    DataTable dtEmp, dtSpa;
    //    DataSet ds = new DataSet();
    //    dtEmp = app.getByAPP_DATE_TIME(dateApp, timeApp, acc_id);
    //    dtSpa = app.getByAPP_DATE_SPA(dateApp, timeApp, acc_id);
    //    if (dtEmp != null)
    //    {
    //        ds.Tables.Add(dtEmp);
    //    }
    //    if (dtSpa != null)
    //    {
    //        ds.Tables.Add(dtSpa);
    //    }

    //    return ds;
    //}
    //[AjaxPro.AjaxMethod]
    //public MyResult loadServiceBySerTypeId(string value, string SerID)
    //{
    //    MyResult My = new MyResult();
    //    DataTable dtser = ser.getBySER_ID(Convert.ToInt32(value), acc_id);
    //    My.tbl = dtser;
    //    My.SerID = SerID;
    //    return My;

    //    //dt = cate.getBySERCATE_ID(Convert.ToInt32(id));
    //    //return dt;
    //}

    //[AjaxPro.AjaxMethod]
    //public MyResult LoadServicePrice(string val, string PriceID)
    //{
    //    MyResult result = new MyResult();
    //    DataTable get = ser.getServices_Price(Convert.ToInt32(val), acc_id);
    //    result.tbl = get;
    //    result.PriceID = PriceID;
    //    return result;
    //}

    //private void LoadClient()
    //{
    //    try
    //    {
    //        dtResult = cl.GetAllClient(acc_id);
    //        ddlClient.DataSource = dtResult;
    //        ddlClient.DataTextField = "CLI_NAME";
    //        ddlClient.DataValueField = "CLI_ID";
    //        ddlClient.DataBind();
    //        ddlClient.Items.Insert(0, new ListItem("-Choose Client Name-", "0"));
    //    }
    //    catch (Exception ex)
    //    {
    //        ex.ToString();
    //    }
    //}



    //[AjaxPro.AjaxMethod]
    //public int addAppointment(string clientId, string empId, string spaId, string serId, string date, string time)
    //{
    //    int id = acc_id;
    //    DateTime datenow = DateTime.Now;

    //    string[] strarry = time.Split(' ');
    //    string result = strarry[0].ToString() + ":00 " + strarry[1].ToString();
    //    string ngay = date + " " + result;
    //    DateTime timeApp = Convert.ToDateTime(ngay);
    //    DateTime dateApp = Convert.ToDateTime(date);
    //    if (timeApp < datenow)
    //    {
    //        //Select date greater than current date !!!
    //        return -1;
    //    }
    //    else
    //    {
    //        int clid = int.Parse(clientId);
    //        app.insertAPPOINTMENTS(ref id, Convert.ToInt32(empId), clid, Convert.ToInt32(spaId), Convert.ToInt32(serId), dateApp, timeApp, STATUS);
    //        return 1;
    //    }
    //}
    //[AjaxPro.AjaxMethod]
    //public string[] addNewClient(string name, string email, string phone)
    //{
    //    int newId = cl.insertClientOutID(acc_id, name, email, phone);

    //    return new string[] { newId + "", name };
    //}
    //private void select_customer(int acc_id)
    //{
    //    DataTable dt = new DataTable();
    //    dt = cl.getByACC_ID(acc_id);
    //    ddlClient.DataSource = dt;
    //    ddlClient.DataTextField = "CLI_NAME";
    //    ddlClient.DataValueField = "CLI_ID";
    //    ddlClient.DataBind();
    //    ddlClient.Items.Insert(0, new ListItem("== Select Item ==", "0"));
    //}

    //private void load_hour_dropdown()
    //{
    //    int intHour = 8;
    //    int intMinute = 0;
    //    string strAP = " AM";
    //    LoadComboBox(intHour, intMinute, strAP);
    //}

    //private void LoadComboBox(int intHour, int intMinute, string strAP)
    //{
    //    try
    //    {
    //        //lstTime.SelectedIndex = -1;
    //        while (true)
    //        {
    //            if (intMinute == 0)
    //            {

    //                lstTime.Items.Add(intHour.ToString() + ":0" + intMinute.ToString() + strAP);
    //                intMinute += 15;
    //                if (intMinute == 60)
    //                {
    //                    intMinute = 0;
    //                    intHour++;
    //                    if (intHour == 12)
    //                    {
    //                        intHour = 12;
    //                        strAP = " PM";
    //                    }
    //                    else if (intHour == 13)
    //                    {
    //                        intHour = 1;
    //                        strAP = " PM";
    //                    }
    //                    if (intHour == 9 && strAP == " PM")
    //                    {
    //                        lstTime.Items.Add(intHour.ToString() + ":" + intMinute.ToString() + strAP);
    //                        break;
    //                    }
    //                }
    //            }
    //            else
    //            {
    //                lstTime.Items.Add(intHour.ToString() + ":" + intMinute.ToString() + strAP);
    //                intMinute += 15;
    //                if (intMinute == 60)
    //                {
    //                    intMinute = 0;
    //                    intHour++;
    //                    if (intHour == 12)
    //                    {
    //                        intHour = 12;
    //                        strAP = " PM";
    //                    }
    //                    else if (intHour == 13)
    //                    {
    //                        intHour = 1;
    //                        strAP = " PM";

    //                    }
    //                    if (intHour == 9 && strAP == " PM")
    //                    {
    //                        lstTime.Items.Add(intHour.ToString() + ":0" + intMinute.ToString() + strAP);
    //                        break;
    //                    }
    //                }
    //            }
    //        }
    //    }
    //    catch (Exception)
    //    {
    //        throw;
    //    }
    //}

    protected void grvShowApp_RowDataBound1(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            
            HiddenField hdf = e.Row.FindControl("hdfCheckOut") as HiddenField;
            //ImageButton btnCheckOut = e.Row.FindControl("btnCheckOut") as ImageButton;
            ImageButton btnCheckOut = e.Row.FindControl("btnCheckOut") as ImageButton;
            //btnCheckOut.Attributes.Add("OnClick", "return showdivSale('" + hdf.Value + "'); return false;");
            //btnCheckOut.PostBackUrl = "#";
            //btnCheckOut.OnClientClick = "return showdivSale('" + hdf.Value + "'); return false;";           
        }    
    } 
    protected void btnCheckOut_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("Appointment_popup.aspx");
    }

    

}
